﻿Imports DMC.Database
Public Class clsChuyenHoSo
   

    Dim Paras1() As String = {"@MaDonViHanhChinh", "@MaHoSoCapGCN"}
    Dim Parasdl() As String = {"@flag", "@MaDonViHanhChinh", "@MaHoSoCapGCN", "@NgayGui", "@NguoiGui", "@LyDoGuiVe"}
    Private strConnection As String ' Khai báo biến nhận chuỗi kết nối Database
    Private strError As String 'Khai bao bien kiem tra loi 
    Private shortAction As Short
    'Trạng thái Hồ sơ cấp GCN

    Private strMaHoSoCapGCN As String

    Private strflag As String = "0"

    Private strMaDonViHanhChinh As String = ""
    Private strngayGui As String = ""
    'Khai bao thuoc tinh ung voi bien 
    Public Property NgayGui() As String
        Get
            Return strngayGui
        End Get
        Set(ByVal value As String)
            strngayGui = value
        End Set
    End Property
    Private strngayNhan As String = ""
    Public Property NgayNhan() As String
        Get
            Return strngayNhan
        End Get
        Set(ByVal value As String)
            strngayNhan = value
        End Set
    End Property
    Private strguidi As String = ""
    Public Property GuiDi() As String
        Get
            Return strguidi
        End Get
        Set(ByVal value As String)
            strguidi = value
        End Set
    End Property
    Private strguive As String = ""
    Public Property GuiVe() As String
        Get
            Return strguive
        End Get
        Set(ByVal value As String)
            strguive = value
        End Set
    End Property
    Private strlydoguive As String = ""
    Public Property LyDoGuiVe() As String
        Get
            Return strlydoguive
        End Get
        Set(ByVal value As String)
            strlydoguive = value
        End Set
    End Property
    Private strMaThuaDat As String = ""
    Public Property MaThuaDat() As String
        Get
            Return strMaThuaDat
        End Get
        Set(ByVal value As String)
            strMaThuaDat = value
        End Set
    End Property
    Private strToBanDo As String = ""
    Public Property ToBanDo() As String
        Get
            Return strToBanDo
        End Get
        Set(ByVal value As String)
            strToBanDo = value
        End Set
    End Property
    Private strSoThua As String = ""
    Public Property SoThua() As String
        Get
            Return strSoThua
        End Get
        Set(ByVal value As String)
            strSoThua = value
        End Set
    End Property
    Private strDiaChi As String = ""
    Public Property DiaChi() As String
        Get
            Return strDiaChi
        End Get
        Set(ByVal value As String)
            strDiaChi = value
        End Set
    End Property
    Private strNguoiGui As String = ""

    Public Property NguoiGui() As String
        Get
            Return strNguoiGui
        End Get
        Set(ByVal value As String)
            strNguoiGui = value
        End Set
    End Property
    Private strNguoiNhan As String = ""

    Public Property NguoiNhan() As String
        Get
            Return strNguoiNhan
        End Get
        Set(ByVal value As String)
            strNguoiNhan = value
        End Set
    End Property

    Public Property MaDonViHanhChinh() As String
        Get
            Return strMaDonViHanhChinh
        End Get
        Set(ByVal value As String)
            strMaDonViHanhChinh = value
        End Set
    End Property




    Public Property Flag() As String
        Get
            Return strflag
        End Get
        Set(ByVal value As String)
            strflag = value
        End Set
    End Property

    'Khai báo thuộc tính nhận chuỗi kết nối Database
    Public WriteOnly Property Connection() As String
        Set(ByVal value As String)
            strConnection = value
        End Set
    End Property
    'Khai báo thuộc tính đọc lỗi phát sinh
    Public ReadOnly Property Err() As String
        Get
            Return strError
        End Get
    End Property

    'Khai bao thuoc tinh ung voi bien shFlag
    Public Property Action() As String
        Get
            Return shortAction
        End Get
        Set(ByVal value As String)
            If value > 3 And value < 0 Then
                value = 0
            End If
            shortAction = value
        End Set
    End Property

    'Khai bao thuoc tinh ung voi bien 
    Public Property MaHoSoCapGCN() As String
        Get
            Return strMaHoSoCapGCN
        End Get
        Set(ByVal value As String)
            strMaHoSoCapGCN = value
        End Set
    End Property
    


    Public Function GetDataDL(ByRef records As DataTable) As String
        Dim strError As String = ""
        Try
            'Khoi tao doi tuong clsDatabase
            Dim Database As New clsDatabase
            'Gán chuỗi kết nối Database
            Database.Connection = strConnection
            If Database.OpenConnection = True Then
                'Neu ket noi co so du lieu thanh cong
                'Khai bao mang gia tri
                Dim Values() As String = {strMaDonViHanhChinh, strMaHoSoCapGCN}
                'Goi phuong thuc GetValue cua doi tuong DMC.clsDatabase
                Database.getValue(records, "spselectktrahosolenquan", Paras1, Values)
                Database.CloseConnection()
                strError = ""
            End If
        Catch ex As Exception
            strError = ex.Message
        End Try
        Return strError
    End Function
    Public Function ExecuteDuLieu(ByRef records As String) As String
        Try
            'Khoi tao doi tuong clsSqlDatabase
            Dim Database As New clsDatabase
            'Neu ket noi co so du lieu thanh cong
            Database.Connection = strConnection
            If Database.OpenConnection = True Then
                'Khai bao mang gia tri
                Dim Values() As String = {shortAction, strMaDonViHanhChinh, strMaHoSoCapGCN, strngayGui, strNguoiGui, strlydoguive}
                'Goi phuong thuc ExecuteSP cua doi tuong clsSQLDatabase
                Database.ExecuteSP("SPDLQuanPhuong", Parasdl, Values, records)
                strError = Database.Err
                Database.CloseConnection()
            End If
        Catch ex As Exception
            strError = ex.Message
        End Try
        Return strError
    End Function

    Public Function SelectTuDienTrangThaiXetDuyet(ByRef strRecords As DataTable) As String
        Try
            'Khai báo và khởi tạo lớp truy xuất cơ sở dữ liệu
            Dim Database As New clsDatabase
            'Khai báo nhận chuỗi kết nối Database
            Database.Connection = strConnection
            'Nếu kết nối thành công
            If Database.OpenConnection = True Then
                'Khai báo mảng giá trị
                Dim arrValues() As String = {}
                Dim arrParas() As String = {}
                'Kiểm tra tính tương thích của cơ sở dữ liệu
                If (arrParas.Length <> arrValues.Length) Then
                    System.Windows.Forms.MessageBox.Show("Mảng giá trị truyền vào không tương thích với mảng tham số", "DMCLand", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Warning)
                    Return "Mảng giá trị truyền vào không tương thích với mảng tham số"
                End If
                'Gọi phương thức thực thi Thủ tục truy vấn cơ sở dữ liệu
                Database.getValue(strRecords, "spSelectTuDienTrangThaiXetDuyet", arrParas, arrValues)
                Database.CloseConnection()
                strError = ""
            End If
        Catch ex As Exception
            strError = ex.Message
        End Try
        Return strError
    End Function
    Public Function UpdateTrangThai() As String
        Dim str As String = ""
        Return ExcuteTrangThai("spUpdateTrangThaiHoSoCapGCN", str)
    End Function
    Public Function ExcuteTrangThai(ByVal strStoreProcedureName As String, ByRef strRecord As String) As String
        Try
            ' Khai bao va khoi tao doi tuong lam viec voi DataBase
            Dim Database As New clsDatabase
            ' Nhan chuoi ket noi 
            Database.Connection = strConnection
            If Database.OpenConnection = True Then
                Dim ParaTrangThai() As String = {"@Flag", "@MaHoSoCapGCN", "@TrangThai", "@MaDonViHanhChinh"}
                Dim ValuesTrangThai() As String = {0, strMaHoSoCapGCN, strflag, strMaDonViHanhChinh}
                If ParaTrangThai.Length <> ValuesTrangThai.Length Then
                    System.Windows.Forms.MessageBox.Show("Độ dài mảng giá trị truyền vào không tương thích", _
                     "DMCLand", Windows.Forms.MessageBoxButtons.OK, Windows.Forms.MessageBoxIcon.Warning)
                    Return "Mảng truyền vào không tương thích"
                End If
                Database.ExecuteSP(strStoreProcedureName, ParaTrangThai, ValuesTrangThai, strRecord)
                strError = Database.Err
                Database.CloseConnection()
            End If
        Catch ex As Exception
            strError = ex.Message
        End Try
        Return strError
    End Function
End Class
